package com.shop.myweb.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

public class ListToPage {


    public static <T> Page<T> listToPage(int currentPage, int pageSize, List<T> list) {
        int listSize = list.size();
        int startIndex = Math.min((currentPage - 1) * pageSize, listSize);
        int endIndex = Math.min(startIndex + pageSize, listSize);
        List<T> records = list.subList(startIndex, endIndex);

        Page<T> page = new Page<>(currentPage, pageSize);
        page.setRecords(records);
        page.setTotal(listSize);

        return page;
    }
}
